{#include main}
{#title}Managed datasources{/title}
{#body}
<table class="table table-striped">
    <thead class="thead-dark">
        <tr>
            <th scope="col">Name</th>
            <th scope="col">Actions</th>
        </tr>
    </thead>
    <tbody>
        {#for container in info:containers}
        <tr>
            <td>
                {container.dataSourceName}
            </td>
            <td>
                <div class="btn-group">
                    {#if container.hasMigrations}
                    <form method="post"  enctype="application/x-www-form-urlencoded">
                        <input type="hidden" name="datasource" value="{container.dataSourceName}">
                        <input type="hidden" name="operation" value="clean">
                        <input id="clear" type="submit" class="btn btn-primary btn-sm" value="Clean" onclick="return confirm('This will drop all objects (tables, views, procedures, triggers, ...) in the configured schema. Do you want to continue?')" >
                    </form>
                    &nbsp;
                    <form method="post"  enctype="application/x-www-form-urlencoded">
                        <input type="hidden" name="datasource" value="{container.dataSourceName}">
                        <input type="hidden" name="operation" value="migrate">
                        <input id="migrate" type="submit" class="btn btn-primary btn-sm" value="Migrate" >
                    </form>
                    {/if}
                    {#if container.createPossible}
                    <!-- Button trigger modal -->
                    <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#{container.id}Modal">
                        Create Initial Migration File
                    </button>
                    
                    {/if}
                </div>
                {#if container.createPossible}
                <i class="fas fa-info-circle float-right" data-toggle="tooltip" data-placement="left" 
                   title="Set up basic files for Flyway migrations to work. Initial file in `db/migrations` will be created and you can then add additional migration files"></i>


                <!-- Modal -->
                <div class="modal fade" id="{container.id}Modal" tabindex="-1" aria-labelledby="{container.id}ModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h5 class="modal-title" id="{container.id}ModalLabel">{container.dataSourceName} Datasource</h5>
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                            <div class="modal-body">
                                Set up an initial file from Hibernate ORM schema generation for Flyway migrations to work. <br/>
                                If you say <span class="badge badge-success">yes</span> an initial file in <span class="badge badge-secondary">db/migrations</span> will be created 
                                and you can then add additional migration files <a href="https://quarkus.io/guides/flyway">as documented</a>.
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-secondary btn-sm" data-dismiss="modal">No</button>
                                <form method="post"  enctype="application/x-www-form-urlencoded" action="create-initial-migration">
                                    <input type="hidden" name="datasource" value="{container.dataSourceName}">
                                    <input id="create" type="submit" class="btn btn-success btn-sm" value="Yes" >
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
                {/if}
            </td>
            {/for}
    </tbody>
</table>

{/body}
{/include}
